//---------------------------------------------------------------------------

#ifndef FormItemsH
#define FormItemsH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "DBCtrlsEh.hpp"
#include "DBGridEh.hpp"
#include "DBGridEhGrouping.hpp"
#include "DBLookupEh.hpp"
#include "FIBDatabase.hpp"
#include "FIBDataSet.hpp"
#include "GridsEh.hpp"
#include "pFIBDatabase.hpp"
#include "pFIBDataSet.hpp"
#include "PropFilerEh.hpp"
#include "PropStorageEh.hpp"
#include <Data.DB.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.Mask.hpp>
#include <Vcl.ToolWin.hpp>
#include <Vcl.Buttons.hpp>
#include "FIBQuery.hpp"
#include "pFIBQuery.hpp"
#include <Vcl.DBCtrls.hpp>
#include <Vcl.Graphics.hpp>
//---------------------------------------------------------------------------
#include "FrameNewMark.h"
#include <map>
using namespace std;
//---------------------------------------------------------------------------
class TItemsForm : public TForm
{
__published:	// IDE-managed Components
	TDBGridEh *DBGridEh;
	TToolBar *ToolBar;
	TToolButton *AddToolButton;
	TToolButton *DeleteToolButton;
	TToolButton *RefreshToolButton;
	TToolButton *EditToolButton;
	TpFIBTransaction *ReadTransaction;
	TpFIBDataSet *DataSet;
	TDataSource *DataSource;
	TImageList *ImageList;
	TpFIBDataSet *CategoriesDataSet;
	TDataSource *CategoriesDataSource;
	TPropStorageEh *PropStorageEh;
	TPanel *EditorPanel;
	TGroupBox *MedDetailsGroupBox;
	TLabel *GenericNameLabel;
	TLabel *AuthLevelLabel;
	TLabel *MedicinalFormLabel;
	TLabel *MedDetailsGroupBoxLabel;
	TDBCheckBoxEh *TracerDBCheckBoxEh;
	TDBLookupComboboxEh *GenericNameDBLookupComboboxEh;
	TDBComboBoxEh *AuthLevelDBComboBoxEh;
	TDBLookupComboboxEh *MedFormDBLookupComboboxEh;
	TDBGridEh *PharmGroupsSetDBGridEh;
	TpFIBDataSet *BasicUnitsDataSet;
	TDataSource *BasicUnitsDataSource;
	TpFIBDataSet *ItemNamesDataSet;
	TDataSource *ItemNamesDataSource;
	TDataSource *GenericNamesDataSource;
	TpFIBDataSet *GenericNamesDataSet;
	TDataSource *MedFormsDataSource;
	TpFIBDataSet *MedFormsDataSet;
	TpFIBDataSet *PharmGroupsSetDataSet;
	TDataSource *PharmGroupsSetDataSource;
	TButton *SaveButton;
	TGroupBox *ItemGroupBox;
	TLabel *ItemNameLabel;
	TLabel *CategoryLabel;
	TDBLookupComboboxEh *CategoryDBLookupComboboxEh;
	TDBLookupComboboxEh *ItemNameDBLookupComboboxEh;
	TPanel *EditorCaptionPanel;
	TToolButton *ToolButton1;
	TToolButton *ToolButton2;
	TToolButton *ToolButton3;
	TToolButton *ToolButton4;
	TpFIBTransaction *WriteTransaction;
	TLabel *PharmGroupsLabel;
	TSpeedButton *PharmGroupsSpeedButton;
	TLabel *EditorCaptionLabel2;
	TLabel *EditorCaptionLabel3;
	TpFIBQuery *AddPharmGroupQuery;
	TpFIBQuery *ClearPharmGroupSetQuery;
	TLabel *DosageLabel;
	TDBEditEh *DosageDBEditEh;
	TpFIBQuery *UpdateInsertItemQuery;
	TpFIBQuery *DeleteItemQuery;
	TpFIBQuery *UpdateInsertItemDrugQuery;
	TpFIBQuery *DeleteItemDrugQuery;
	TLabel *BasicUnitLabel;
	TLabel *DescriptionLabel;
	TDBLookupComboboxEh *BasicUnitDBLookupComboboxEh;
	TDBCheckBoxEh *IsHazardousDBCheckBoxEh;
	TDBEditEh *DescriptionDBEditEh;
	TDBCheckBoxEh *GenNameAsItemNameDBCheckBoxEh;
	TSpeedButton *CloseEditorSpeedButton;
	TButton *CancelButton;
	TLabel *TempRegimeLabel;
	TDBLookupComboboxEh *TempRegimeDBLookupComboboxEh;
	TpFIBDataSet *TempRegimesDataSet;
	TDataSource *TempRegimesDataSource;
	TPanel *FiltersPanel;
	TToolButton *FiltersToolButton;
	TToolButton *ToolButton6;
	TPanel *FiltersCaptionPanel;
	TLabel *Label3;
	TSpeedButton *CloseFiltersSpeedButton;
	TPanel *LeftFiltersPanel;
	TPanel *RightFiltersPanel;
	TGroupBox *ItemsFilterGroupBox;
	TLabel *ItemNameFilterLabel;
	TLabel *CategoryFilterLabel;
	TDBLookupComboboxEh *ItemNameFilterDBLookupComboboxEh;
	TDBLookupComboboxEh *CategoryFilterDBLookupComboboxEh;
	TGroupBox *MedicineFilterGroupBox;
	TLabel *GenericNameFilterLabel;
	TLabel *AuthLevelFilterLabel;
	TLabel *MedicineFilterGroupBoxLabel;
	TLabel *TempRegimeFilterLabel;
	TDBLookupComboboxEh *GenericNameFilterDBLookupComboboxEh;
	TDBComboBoxEh *AuthLevelFilterDBComboBoxEh;
	TDBLookupComboboxEh *TempRegimeFilterDBLookupComboboxEh;
	TButton *ApplyFiltersButton;
	TpFIBDataSet *ItemNameFilterDataSet;
	TDataSource *ItemNameFilterDataSource;
	TpFIBDataSet *CategoriesFilterDataSet;
	TDataSource *CategoriesFilterDataSource;
	TpFIBDataSet *GenericNamesFilterDataSet;
	TDataSource *GenericNamesFilterDataSource;
	TpFIBDataSet *TempRegimesFilterDataSet;
	TDataSource *TempRegimesFilterDataSource;
	TButton *ResetFiltersButton;
	TLabel *PharmGroupFilterLabel;
	TDBLookupComboboxEh *PharmGroupFilterDBLookupComboboxEh;
	TDataSource *PharmGroupsFilterDataSource;
	TpFIBDataSet *PharmGroupsFilterDataSet;
	TDBCheckBoxEh *HazardousOnlyDBCheckBoxEh;
	TDBCheckBoxEh *TracerOnlyDBCheckBoxEh;
	TImage *EditMarkImage;
	TpFIBQuery *MRUCategoriesQuery;
	void __fastcall FormShow(TObject *Sender);
	void __fastcall FormHide(TObject *Sender);
	void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
	void __fastcall DBGridEhSortMarkingChanged(TObject *Sender);
	void __fastcall AddToolButtonClick(TObject *Sender);
	void __fastcall DeleteToolButtonClick(TObject *Sender);
	void __fastcall EditToolButtonClick(TObject *Sender);
	void __fastcall RefreshToolButtonClick(TObject *Sender);
	void __fastcall SaveButtonClick(TObject *Sender);
	void __fastcall DBGridEhDblClick(TObject *Sender);
	void __fastcall DBGridEhKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall DBLookupComboboxEhKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall EhKeyPress(TObject *Sender, System::WideChar &Key);
	void __fastcall GenericNameDBLookupComboboxEhValueChanged(TObject *Sender);
	void __fastcall PharmGroupsSetDBGridEhEnter(TObject *Sender);
	void __fastcall PharmGroupsSetDBGridEhExit(TObject *Sender);
	void __fastcall PharmGroupsSetDBGridEhKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall PharmGroupsSetDBGridEhColumnsGetCellParams(TObject *Sender, bool EditMode,
		  TColCellParamsEh *Params);
	void __fastcall PharmGroupsSetDBGridEhDblClick(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall ItemNameDBLookupComboboxEhValueChanged(TObject *Sender);
	void __fastcall CategoriesDBLookupComboboxEhValueChanged(TObject *Sender);
	void __fastcall DBLookupComboboxEhDropDownButtonClick(TObject *Sender, bool &Handled);
	void __fastcall DBComboBoxEhDropDownButtonClick(TObject *Sender, bool &Handled);
	void __fastcall GenNameAsItemNameDBCheckBoxEhClick(TObject *Sender);
	void __fastcall CategoriesDBLookupComboboxEhExit(TObject *Sender);
	void __fastcall BasicUnitDBLookupComboboxEhValueChanged(TObject *Sender);
	void __fastcall MedFormDBLookupComboboxEhValueChanged(TObject *Sender);
	void __fastcall PharmGroupsSetDBGridEhCellClick(TColumnEh *Column);
	void __fastcall PharmGroupsSetDBGridEhSumListAfterRecalcAll(TObject *Sender);
	void __fastcall ItemNameDBLookupComboboxEhEditButtonClick(TObject *Sender, bool &Handled);
	void __fastcall CategoriesDBLookupComboboxEhEditButtonClick(TObject *Sender, bool &Handled);
	void __fastcall BasicUnitDBLookupComboboxEhEditButtonClick(TObject *Sender, bool &Handled);
	void __fastcall GenericNameDBLookupComboboxEhEditButtonClick(TObject *Sender,
		  bool &Handled);
	void __fastcall MedFormDBLookupComboboxEhEditButtonClick(TObject *Sender, bool &Handled);
	void __fastcall PharmGroupsSpeedButtonClick(TObject *Sender);
	void __fastcall CloseEditorSpeedButtonClick(TObject *Sender);
	void __fastcall CancelButtonClick(TObject *Sender);
	void __fastcall TempRegimeDBLookupComboboxEhChange(TObject *Sender);
	void __fastcall FiltersToolButtonClick(TObject *Sender);
	void __fastcall CloseFiltersSpeedButtonClick(TObject *Sender);
	void __fastcall ApplyFiltersButtonClick(TObject *Sender);
	void __fastcall CategoryFilterDBLookupComboboxEhKeyValueChanged(TObject *Sender);
	void __fastcall ResetFiltersButtonClick(TObject *Sender);
	void __fastcall FiltersPanelResize(TObject *Sender);
	void __fastcall DBGridEhColumns0AdvDrawDataCell(TCustomDBGridEh *Sender, TGridCoord &Cell,
		  TGridCoord &AreaCell, TColumnEh *Column, const TRect &ARect, TColCellParamsEh *&Params,
		  bool &Processed);
	void __fastcall TempRegimeDBLookupComboboxEhEnter(TObject *Sender);
private:	// User declarations
	void __fastcall AddNewMark(TWinControl* Control);
	void __fastcall DeleteNewMark(TWinControl* Control);
	enum EDITOR_MODE {emApply, emCancel, emAsk};
	struct {
		int ItemID;
		String ItemName;
		String Category;
		String BasicUnit;
		bool IsHazardous;
		String Description;
		String GenericName;
		String MedForm;
		String Dosage;
		String TempRegime;
		String AuthLevel;
		bool IsTraced;
	} EditorSavedData;
	DWORD NumberEditChangedTicks;
	map <TWinControl*, TNewMarkFrame*> NewMarks;
	typedef map <int, int> CATEGORY_CNT;
	typedef map <int, CATEGORY_CNT> NAME_CATEGORY_CNT;
	NAME_CATEGORY_CNT CategoryMruTable;

public:		// User declarations
	bool IsPharmGroupsSetChanged;
	__fastcall TItemsForm(TComponent* Owner);
	void __fastcall EditModeOn(bool NewItem);
	bool __fastcall EditModeOff(bool Accept);
	bool __fastcall EditorDataChanged();
	bool __fastcall CheckRequiredFields();
};
//---------------------------------------------------------------------------
extern PACKAGE TItemsForm *ItemsForm;
//---------------------------------------------------------------------------
#endif
